<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html
  PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html lang="en-us" xml:lang="en-us">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<meta name="DC.Type" content="task"/>
<meta name="DC.Title" content="Adding native support to an Android project"/>
<meta name="abstract" content="Android projects that have native support build the native components along with those rest of the project. At build time the Sequoyah Android feature compiles the native (C/C++) code into a shared library and then includes that shared library in the project APK."/>
<meta name="description" content="Android projects that have native support build the native components along with those rest of the project. At build time the Sequoyah Android feature compiles the native (C/C++) code into a shared library and then includes that shared library in the project APK."/>
<meta name="DC.Relation" scheme="URI" content="../topics/t_native-apps-about.html"/>
<meta name="DC.Relation" scheme="URI" content="../topics/t_native-classes-generating.html"/>
<meta name="DC.Relation" scheme="URI" content="../topics/t_config-for-native.html"/>
<meta name="copyright" content="Motorola Mobility, Inc. 2009-2011" type="primary"/>
<meta name="DC.Rights.Owner" content="Motorola Mobility, Inc. 2009-2011" type="primary"/>
<meta name="DC.Format" content="XHTML"/>
<meta name="DC.Identifier" content="t_project-adding-native"/>
<meta name="DC.Language" content="en-us"/>
<link rel="stylesheet" type="text/css" href="../commonltr.css"/>
<title>Adding native support to an Android project</title>
</head>
<body id="t_project-adding-native"><a name="t_project-adding-native"><!-- --></a>
<a class="hdr-none"/>

  <h1 class="topictitle1">Adding native support to an Android project</h1>

  
  
  <div><p>Android projects that have native support build the native components along with those rest of the project.
    At build time the Sequoyah Android feature compiles the native (C/C++) code into a shared library and then includes
    that shared library in the project APK.</p>

    <div class="p">You must have configured your development environment to allow native development before you can add native
      support to a given Android project.</div>

    <div class="section"/>

    <ol>
      <li>
        <span>You add native support to an existing Android project. If you are running MOTODEV Studio for Android you
          also have the option to add it when you first create the project.</span>
        <ul>
          <li>If you are running MOTODEV Studio for Android and have not yet created your project, do so with
              <span class="menucascade"><span class="uicontrol">File</span> &gt; <span class="uicontrol">New</span> &gt; <span class="uicontrol">Android Project Using Studio
                for Android</span></span>, and at the bottom of the New Android Project dialog select the
              <span class="uicontrol">Add native support</span> option.</li>

          <li>If you are running Eclipse and have not yet created your project, create it as you normally would, and
            then add native support as detailed in the next option.</li>

          <li>If your project already exists, right-click it in the Package Explorer and select <span class="menucascade"><span class="uicontrol">Android Tools</span> &gt; <span class="uicontrol">Add Native Support</span></span>. In the
            dialog that appears, verify the <span class="uicontrol">Library name</span> field and click <span class="uicontrol">Finish</span>. The <span class="uicontrol">Library name</span> is the base name of the native shared library
            that will be created when your app is built (the full name of the library will have a "lib" prefix and an
            extension of ".so").</li>

        </ul>

         After adding native support your project will now have a "jni" directory with a makefile (<span class="filepath">Android.mk</span>) and one or more <span class="filepath">.cpp</span> files; this directory is where you do your
          native development. When your project builds you will find the native shared library in your project's
            <span class="filepath">libs/armeabi</span> directory.
      </li>

    </ol>

    <div class="section">You can now create your C/C++ code (in the jni directory); you will likely want to switch to the C/C++
      perspective to do this. When you build your project the native code is compiled into the shared library which is
      then included as part of your APK. Also note that you will need to load your native library from your Java code by
      calling <samp class="codeph">System.loadLibrary()</samp>. See the sample applications that are included with the Android NDK
      for tips on how and when to do this.</div>

  </div>

<div>
<div class="familylinks">
<div class="parentlink"><strong>Parent topic:</strong> <a href="../topics/t_native-apps-about.html" title="From within Eclipse you can develop Android applications that include native code. Once you have installed the necessary components and properly configured your development environment, for Android projects that have been enabled for native support your C/C++ code is compiled into a shared library that is included when the Java portions of your project are built. The Sequoyah Android feature provides other native application support: for instance, you can generate C++ classes from native method declarations in your Java source files.">Native Android Application Development</a></div>
</div>
<div class="relinfo"><strong>Related tasks</strong><br/>
<div><a href="../topics/t_native-classes-generating.html" title="The Sequoyah Android feature lets you generate C++ classes from native method declarations in your Java source files. This allows you to focus on the native function implementations, rather than the mechanics of parameter passing between Java and native C/C++ code.">Generating native classes</a></div>
<div><a href="../topics/t_config-for-native.html" title="After installing the Android NDK and a few other needed components, Eclipse can be configured to let you develop Android applications that include native (C/C++) code.">Configuring your development environment for native development</a></div>
</div>
</div>

</body>
</html>